<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	    		xmlns:ui="http://java.sun.com/jsf/facelets"
	  			xmlns:h="http://java.sun.com/jsf/html"
	  			xmlns:f="http://java.sun.com/jsf/core"                
                xmlns:cs="http://myfaces.apress.com/custom"
				template="/WEB-INF/layouts/standard.xhtml"
				xmlns:a4j="http://richfaces.org/a4j"
				xmlns:rich="http://richfaces.org/rich"
				xmlns:bf="http://www.bssmanager.com/jsf"
				xmlns:c="http://java.sun.com/jstl/core">
				
				
	<ui:define name="formheader">
		<h2>Rooms</h2>
	</ui:define>
	
	<ui:define name="formGlobal">
		<bf:dateSelector controller="#{roomController}"  date="date" ajaxUpdate="false"/>
	</ui:define>

	<ui:define name="content">
	
		<c:set var="controller" value="#{roomController}"/>

		<h:messages errorClass="errors" style="color:#ff1111" />
			
			<h:form id="#{controller.modelName}">
			
				<rich:panel style="border:0">
					<f:facet name="header">
						<h:outputText value="Add New Room"/>
					</f:facet>
					<h:panelGrid columns="2">						
						<h:outputLabel value="Room Number:" />
						<h:outputText rendered="#{controller.editing}" value="#{controller.model.roomNumber}" />
						<h:inputText rendered="#{not controller.editing}" value="#{controller.model.roomNumber}" />
						<h:outputLabel value="Building:" />
						<h:outputText rendered="#{controller.editing}" value="#{controller.model.building}" converter="#{buildingConverter}"/>
						<rich:comboBox rendered="#{not controller.editing}"
										id="roomBuilding" 
										value="#{controller.model.building}"
										suggestionValues="#{buildingController.all}"
										converter="#{buildingConverter}">								
						</rich:comboBox>
						<h:outputLabel value="Floor:" />
						<h:inputText value="#{controller.model.floor}" />
						<h:outputLabel value="Number of Beds:" />
						<h:inputText value="#{controller.model.numberOfBeds}" />
						<h:outputLabel value="Is Dormitory ? :" />
						<h:selectBooleanCheckbox id="isDormitory" value="#{controller.model.dormitory}"/>
						<h:outputLabel value="Has AC? :" />
						<h:selectBooleanCheckbox id="hasDormitory" value="#{controller.model.ac}"/>
						<h:outputLabel rendered="false" value="Rate:" />
						<h:inputText  rendered="false" value="#{controller.model.rate}" />
					</h:panelGrid>
					<h:panelGroup>
						<h:commandButton rendered="#{not controller.editing}" id="submit" action="#{controller.add}" value="Add"/>
						<rich:spacer width="5px"/>
						<h:commandButton rendered="#{controller.editing}" action="#{controller.update}" value="Update"/>
						<rich:spacer width="5px"/>
						<h:commandButton id="cancel" value="Cancel" action="#{controller.cancel}"/>
					</h:panelGroup>	
				</rich:panel>									
			
				<rich:panel style="border:0">
					<f:facet name="header">
						<h:outputText value="All Rooms"/>
					</f:facet>
					<rich:dataTable value="#{controller.data}" var="aBean" rowKeyVar="rowVar">
						<rich:column>
							<f:facet name="header">
								<h:outputText value="S/N" />
							</f:facet>
							<h:outputText value="${rowVar+1}"/>
						</rich:column>						
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Edit" />
							</f:facet>
							<h:commandButton style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}" title="#{controller.editing ? 'Edit already in progress...':'Click to Edit'}" image="/resrc/images/edit1.jpg"   disabled="#{controller.editing}" action="${controller.select}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Delete" />
							</f:facet>
							<h:commandButton title="#{controller.editing ? 'Edit is in progress, please complete the editing...':'Click to Delete'}" image="/resrc/images/cross1.jpg" 
							style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}" action="${controller.remove}" immediate="true" disabled="#{controller.editing}"
							onclick="if(!showConfirmation('Are you sure to remove #{controller.modelName}: #{aBean.roomNumber} ?')) return false;"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Building</f:facet>
							<h:outputText value="#{aBean.building.name}"/>
						</rich:column>			
						<rich:column>
							<f:facet name="header">Room Number</f:facet>
							<h:outputText value="#{aBean.roomNumber}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Floors</f:facet>
							<h:outputText value="#{aBean.floor}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Dormitory</f:facet>
							<h:outputText value="#{aBean.dormitory ? 'Yes':'No'}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">AC</f:facet>
							<h:outputText value="#{aBean.ac ? 'Yes':'No'}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Beds</f:facet>
							<h:outputText value="#{aBean.numberOfBeds}"/>
						</rich:column>						
						<f:facet name="footer">
							<h:outputText rendered="#{controller.data.rowCount le 0}" value="No rooms found..." />
							<h:outputText rendered="#{controller.data.rowCount gt 0}" value="#{controller.data.rowCount} rooms found..." />
						</f:facet>
					</rich:dataTable>
				</rich:panel>
			</h:form>

	</ui:define>
</ui:composition>